package jmine.tec.web.front.sample;

import static jmine.tec.web.front.domain.BackOfficeRequestPropertyBigDecimalBuilder.aBigDecimalProperty;
import static jmine.tec.web.front.domain.BackOfficeRequestPropertyDateBuilder.aDateProperty;
import static jmine.tec.web.front.domain.BackOfficeRequestPropertyStringBuilder.aStringProperty;
import jmine.tec.web.front.dao.BackOfficeRequestPropertySystemIdentifier;
import jmine.tec.web.front.dao.BackOfficeRequestTypeSystemIdentifier;
import jmine.tec.web.front.domain.BackOfficeRequestPropertyBigDecimal;
import jmine.tec.web.front.domain.BackOfficeRequestPropertyDate;
import jmine.tec.web.front.domain.BackOfficeRequestPropertyString;
import jmine.tec.web.front.domain.BackOfficeRequestType;
import jmine.tec.web.front.domain.BackOfficeRequestTypeBuilder;

/**
 * Sample postscript information
 */
public class SampleFormTypeInformation {

    public static BackOfficeRequestTypeSystemIdentifier TYPE_IDENTIFIER = null;

    public static BackOfficeRequestPropertySystemIdentifier STRING_PROPERTY_IDENTIFIER = null;

    public static BackOfficeRequestPropertySystemIdentifier NUMBER_PROPERTY_IDENTIFIER = null;

    public static BackOfficeRequestPropertySystemIdentifier DATE_PROPERTY_IDENTIFIER = null;

    public static BackOfficeRequestType TYPE;

    public static BackOfficeRequestPropertyString STRING_PROPERTY;

    public static BackOfficeRequestPropertyBigDecimal NUMBER_PROPERTY;

    public static BackOfficeRequestPropertyDate DATE_PROPERTY;

    public static void prepare() {
        TYPE = BackOfficeRequestTypeBuilder.aRequestType().build();
        STRING_PROPERTY = aStringProperty().mnemonic("string").description("Sample String").save();
        NUMBER_PROPERTY = aBigDecimalProperty().mnemonic("number").description("Sample Number").save();
        DATE_PROPERTY = aDateProperty().mnemonic("date").description("Sample Date").save();
        TYPE.addProperty(STRING_PROPERTY);
        TYPE.addProperty(DATE_PROPERTY);
        TYPE.addProperty(NUMBER_PROPERTY);
        TYPE.getPersister().save();

        TYPE_IDENTIFIER = new MockTypeIdentifier(TYPE.getId());
        STRING_PROPERTY_IDENTIFIER = new MockPropertyIdentifier(STRING_PROPERTY.getId());
        NUMBER_PROPERTY_IDENTIFIER = new MockPropertyIdentifier(NUMBER_PROPERTY.getId());
        DATE_PROPERTY_IDENTIFIER = new MockPropertyIdentifier(DATE_PROPERTY.getId());

        BackOfficeRequestType otherType = BackOfficeRequestTypeBuilder.aRequestType().mnemonic("type2").build();
        otherType.addProperty(aStringProperty().mnemonic("stringA").description("Sample String A").save());
        otherType.addProperty(aBigDecimalProperty().mnemonic("numberA").description("Sample Number A").save());
        otherType.getPersister().save();

        otherType = BackOfficeRequestTypeBuilder.aRequestType().mnemonic("type3").build();
        otherType.addProperty(aStringProperty().mnemonic("stringB").description("Sample String B").save());
        otherType.getPersister().save();

        otherType = BackOfficeRequestTypeBuilder.aRequestType().mnemonic("type4").build();
        otherType.addProperty(aDateProperty().mnemonic("dateC").description("Other Sample Date C").save());
        otherType.getPersister().save();
    }

    private static final class MockTypeIdentifier implements BackOfficeRequestTypeSystemIdentifier {

        private Long id;

        public MockTypeIdentifier(Long id) {
            this.id = id;
        }

        public Long getSystemId() {
            return this.id;
        }
    }

    private static final class MockPropertyIdentifier implements BackOfficeRequestPropertySystemIdentifier {

        private Long id;

        public MockPropertyIdentifier(Long id) {
            this.id = id;
        }

        public Long getSystemId() {
            return this.id;
        }
    }
}
